package com.itheima.controller;

import com.itheima.domain.po.Emp;
import com.itheima.domain.po.LoginResult;
import com.itheima.domain.vo.Result;
import com.itheima.service.EmpService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "用户登录", description = "用户登录相关接口")
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private EmpService empService;

    @Operation(summary = "用户登录", description = "系统用户登录接口")
    @PostMapping
    public Result login(@Parameter(description = "登录信息") @RequestBody Emp emp) {
        // 校验返回结果是否为空
        LoginResult login = empService.login(emp);
        if (login == null) {
            return Result.error("用户名或密码错误");
        }
        return Result.success(login);
    }
}
